//初始化Toastr主题
toastr.options = {
    "closeButton": true,
    "debug": false,
    "progressBar": true,
    "preventDuplicates": false,
    "positionClass": "toast-top-right",
    "onclick": null,
    "showDuration": "400",
    "hideDuration": "1000",
    "timeOut": "7000",
    "extendedTimeOut": "1000",
    "showEasing": "swing",
    "hideEasing": "linear",
    "showMethod": "fadeIn",
    "hideMethod": "fadeOut"
}
//定义消息提示函数
function showMsg(message, type) {
    toastr[type](message);
}

function showError(e) {
    var error = e.responseJSON.msg;
    var arr = Object.values(error);
    showMsg(arr[0], 'error');
}

;(function($){
    //绑定登陆页提交按钮点击事件
    $('#login_form').on('submit', function(){
        var l = $('#login_submit').ladda();
        l.ladda( 'start' );
        $.ajax({
            url: '/dologin',
            method: 'post',
            data: $('#login_form').serialize(),
            success: function(result){
                if (result.status == 1) {
                    window.location.href = '/';
                } else {
                    l.ladda('stop');
                    showMsg(result.message, 'error');
                }
            }
        });
        return false;
    });
    $('#side-nav').metisMenu();
    //绑定Side-Nav点击添加Active class
    $('#side-nav>li').not('.nav-header').has('a').click(function(){
        //$('#side-nav .active').removeClass('active');
        //$(this).addClass('active');
    });
    //绑定Side-Nav的点击事件
    $('a[data-bind="side-nav"]').on('click', function(){
        var data_nav = $(this).attr('data-nav');
        $('#mainContent-wrapper .mainContent-box').hide();
        $('#mainContent-wrapper #' + data_nav).show();
    });

    // //用户列表
    // $('#user_list').bootstrapTable({
    //     url: '/user',
    //     pagination:true,
    //     showRefresh:true,
    //     sidePagination:'server',
    //     onLoadSuccess :function (data) {
    //         var rows = data.rows;
    //         rows.forEach(function (item) {
    //             item.usercontrol = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#detailUser" data-bid="' + item.id + '"><i class="fa fa-align-justify"></i></button> <button type="button" class="btn-danger btn-xs" data-toggle="UserDelete"  data-bid="' + item.id + '"><i class="fa fa-exclamation-circle"></i></button>';
    //         });
    //         $('#user_list').bootstrapTable('load', data);
    //         stop_btn('UserDelete', 'user/changeStatus', 'user');
    //     }
    // });
    // 
    
    // recharge_member 列表
    $('#recharge_member_list').bootstrapTable({
        url: '/recharge_member',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                switch (item.is_pay) {
                    case 1 :
                        item.is_pay = '已支付';
                        break;
                    case 2 :
                        item.is_pay = '未支付';
                        break;
                    default :
                        item.is_pay = '未定义卡类型';
                }
               item.control = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#111111111111" data-bid="' + item.id + '" title="查看详情"><i class="fa fa-align-justify"></i></button> <button type="button" class="btn-danger btn-xs" data-toggle="1111111111"  data-bid="' + item.id + '" title="修改状态" data-list="banner_list"><i class="fa fa-exclamation-circle"></i></button>';
            });
            $('#recharge_member_list').bootstrapTable('load', data);
            stop_btn('1111111111', 'banner/changeStatus', 'banner');
        }
    });

    // Banner 列表
    $('#banner_list').bootstrapTable({
        url: '/banner',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
               item.status = (item.status == 1) ?
                   '<button type="button" class="btn-xs btn-primary"><i class="fa fa-check"></i></button>'
                   : '<button type="button" class="btn-xs btn-danger"><i class="fa fa-warning"></i></button>';
               item.control = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#detailBanner" data-bid="' + item.id + '" title="查看详情"><i class="fa fa-align-justify"></i></button> <button type="button" class="btn-danger btn-xs" data-toggle="deleteBanner"  data-bid="' + item.id + '" title="修改状态" data-list="banner_list"><i class="fa fa-exclamation-circle"></i></button>';
            });
            $('#banner_list').bootstrapTable('load', data);
            stop_btn('deleteBanner', 'banner/changeStatus', 'banner');
        }
    });

    // Banner 列表
    $('#product_banner_list').bootstrapTable({
        url: '/product_banner',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
               item.status = (item.status == 1) ?
                   '<button type="button" class="btn-xs btn-primary"><i class="fa fa-check"></i></button>'
                   : '<button type="button" class="btn-xs btn-danger"><i class="fa fa-warning"></i></button>';
                   item.url = '<a href="' + item.img.url + '" data-gallery="" title="点击查看大图"><img src="' + item.img.url + '" width="50px"></img></a>';
               item.control = '<button type="button" class="btn-danger btn-xs" data-toggle="deleteBanner"  data-bid="' + item.id + '" title="修改状态" data-list="banner_list"><i class="fa fa-exclamation-circle"></i></button>';
               item.banner_id = '商品轮播图';
            });
            $('#product_banner_list').bootstrapTable('load', data);
            stop_btn('deleteBanner', 'product_banner/changeStatus', 'productBanner');
        }
    });

    // Banner_item 列表
    $('#banner_item_list').bootstrapTable({
        url: '/banner_item',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                item.name = item.banner.name;
                item.description = item.banner.description;
                item.banner_status = (item.banner.status == 1) ?
                    '<button type="button" class="btn-xs btn-primary"><i class="fa fa-check"></i></button>'
                    : '<button type="button" class="btn-xs btn-danger"><i class="fa fa-warning"></i></button>';
                item.status = (item.banner.status == 1) ?
                    '<button type="button" class="btn-xs btn-primary"><i class="fa fa-check"></i></button>'
                    : '<button type="button" class="btn-xs btn-danger"><i class="fa fa-warning"></i></button>';
                item.image = '<a href="' + item.img.url + '" data-gallery="" title="点击查看大图"><img src="' + item.img.url + '" width="50px"></img></a>';
                item.control = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#detailBannerItem" data-bid="' + item.id + '" title="查看详情"><i class="fa fa-align-justify"></i></button> <button type="button" class="btn-danger btn-xs" data-toggle="deleteBanner"  data-bid="' + item.id + '" title="修改状态"><i class="fa fa-exclamation-circle"></i></button>';
            });
            $('#banner_item_list').bootstrapTable('load', data);
            stop_btn('deleteBannerItem', 'banner_item/changeStatus');
        }
    });

    // Image 列表
    $('#image_list').bootstrapTable({
        url: '/image',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                item.status = (item.status == 1) ?
                    '<button type="button" class="btn-xs btn-primary"><i class="fa fa-check"></i></button>'
                    : '<button type="button" class="btn-xs btn-danger"><i class="fa fa-warning"></i></button>';
                item.url = '<a href="' + item.url + '" data-gallery="" title="点击查看大图"><img src="' + item.url + '" width="50px"></img></a>';
                item.control = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#detailImage" data-bid="' + item.id + '" title="查看详情"><i class="fa fa-align-justify"></i></button> <button type="button" class="btn-danger btn-xs" data-toggle="deleteImage"  data-bid="' + item.id + '" title="修改图片状态" data-list="image_list"><i class="fa fa-exclamation-circle"></i></button>';
            });
            $('#image_list').bootstrapTable('load', data);
            stop_btn('deleteImage', 'image/changeStatus');
        }
    });

    // Theme 列表
    $('#theme_list').bootstrapTable({
        url: '/theme',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                item.status = (item.status == 1) ?
                    '<button type="button" class="btn-xs btn-primary"><i class="fa fa-check"></i></button>'
                    : '<button type="button" class="btn-xs btn-danger"><i class="fa fa-warning"></i></button>';
                item.topic_image_id = '<a href="' + item.topic_img.url + '" data-gallery="" title="点击查看大图"><img src="' + item.topic_img.url + '" width="50px"></img></a>';
                item.head_image_id = '<a href="' + item.head_img.url + '" data-gallery="" title="点击查看大图"><img src="' + item.head_img.url + '" width="50px"></img></a>';
                item.control = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#detailTheme" data-bid="' + item.id + '" title="查看详情"><i class="fa fa-align-justify"></i></button> <button type="button" class="btn-danger btn-xs" data-toggle="deleteTheme"  data-bid="' + item.id + '" title="修改图片状态" data-list="theme_list"><i class="fa fa-exclamation-circle"></i></button>';
            });
            $('#theme_list').bootstrapTable('load', data);
            stop_btn('deleteTheme', 'theme/changeStatus');
        }
    });

    // Product 列表
    $('#product_list').bootstrapTable({
        url: '/product',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                item.status = (item.status == 1) ?
                    '<button type="button" class="btn-xs btn-primary"><i class="fa fa-check"></i></button>'
                    : '<button type="button" class="btn-xs btn-danger"><i class="fa fa-warning"></i></button>';
                item.product_img = '<a href="' + item.img.url + '" data-gallery="" title="点击查看大图"><img src="' + item.img.url + '" width="50px"></img></a>';
                item.category = item.category.name;
                // item.category = '<a href="' + item.category.url + '" data-gallery="" title="点击查看大图"><img src="' + item.head_img.url + '" width="50px"></img></a>';
                item.control = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#detailProduct" data-bid="' + item.id + '" title="查看详情"><i class="fa fa-align-justify"></i></button> <button type="button" class="btn-danger btn-xs" data-toggle="deleteProduct"  data-bid="' + item.id + '" title="修改图片状态" data-list="product_list"><i class="fa fa-exclamation-circle"></i></button>';
            });
            $('#product_list').bootstrapTable('load', data);
            stop_btn('deleteProduct', 'product/changeStatus');
        }
    });

    // Productproperty 列表
    $('#product_property_list').bootstrapTable({
        url: '/product_property',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                item.product_id = item.product.name;
                item.status = (item.status == 1) ?
                    '<button type="button" class="btn-xs btn-primary"><i class="fa fa-check"></i></button>'
                    : '<button type="button" class="btn-xs btn-danger"><i class="fa fa-warning"></i></button>';
                item.control = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#detailProductProperty" data-bid="' + item.id + '" title="查看详情"><i class="fa fa-align-justify"></i></button>                                                    <button type="button" class="btn-danger btn-xs" data-toggle="deleteProduct"  data-bid="' + item.id + '" title="修改属性状态" data-list="product_list"><i class="fa fa-exclamation-circle"></i></button>';
            });
            $('#product_property_list').bootstrapTable('load', data);
            stop_btn('detailProductProperty', 'product_property/changeStatus');
        }
    });

    // ProductImage 列表
    $('#product_image_list').bootstrapTable({
        url: '/product_image',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                item.status = (item.status == 1) ?
                    '<button type="button" class="btn-xs btn-primary"><i class="fa fa-check"></i></button>'
                    : '<button type="button" class="btn-xs btn-danger"><i class="fa fa-warning"></i></button>';
                item.name  = item.product.name;
                item.product_info_img = '<a href="' + item.img.url + '" data-gallery="" title="点击查看大图"><img src="' + item.img.url + '" width="50px"></img></a>';
                item.product_img = '<a href="' + item.product.url + '" data-gallery="" title="点击查看大图"><img src="' + item.product.url + '" width="50px"></img></a>';
                item.control = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#detailProductImage" data-bid="' + item.id + '" title="查看详情"><i class="fa fa-align-justify"></i></button> <button type="button" class="btn-danger btn-xs" data-toggle="deleteProductImage"  data-bid="' + item.id + '" title="修改图片状态" data-list="product_image_list"><i class="fa fa-exclamation-circle"></i></button>';
            });
            $('#product_image_list').bootstrapTable('load', data);
            stop_btn('deleteProductImage', 'product_image/changeStatus');
        }
    });

    // product_info_list 列表
    $('#product_info_list').bootstrapTable({
        url: '/product_info',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                item.status = (item.status == 1) ?
                    '<button type="button" class="btn-xs btn-primary"><i class="fa fa-check"></i></button>'
                    : '<button type="button" class="btn-xs btn-danger"><i class="fa fa-warning"></i></button>';
                item.is_home = (item.is_home == 1) ?
                    '<button type="button" class="btn-xs btn-primary"><i class="fa fa-check"></i></button>'
                    : '<button type="button" class="btn-xs btn-danger"><i class="fa fa-warning"></i></button>';
                item.name  = item.product.name;
                item.product_image = '<a href="' + item.product.url + '" data-gallery="" title="点击查看大图"><img src="' + item.product.url + '" width="50px"></img></a>';
                item.url = '<a href="' + item.url + '" data-gallery="" title="点击查看大图"><img src="' + item.url + '" width="50px"></img></a>';
                item.control = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#detailProductInfo" data-bid="' + item.id + '" title="查看详情"><i class="fa fa-align-justify"></i></button> <button type="button" class="btn-danger btn-xs" data-toggle="deleteProductInfo"  data-bid="' + item.id + '" title="修改图片状态" data-list="product_info_list"><i class="fa fa-exclamation-circle"></i></button>';
            });
            $('#product_info_list').bootstrapTable('load', data);
            stop_btn('deleteProductInfo', 'product_info/changeStatus');
        }
    });

    // category 列表
    $('#category_list').bootstrapTable({
        url: '/category',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                item.status = (item.status == 1) ?
                    '<button type="button" class="btn-xs btn-primary"><i class="fa fa-check"></i></button>'
                    : '<button type="button" class="btn-xs btn-danger"><i class="fa fa-warning"></i></button>';
                item.topic_img = '<a href="' + item.img.url + '" data-gallery="" title="点击查看大图"><img src="' + item.img.url + '" width="50px"></img></a>';
                item.control = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#detailCategory" data-bid="' + item.id + '" title="查看详情"><i class="fa fa-align-justify"></i></button> <button type="button" class="btn-danger btn-xs" data-toggle="deleteCategory"  data-bid="' + item.id + '" title="修改状态" data-list="category_list"><i class="fa fa-exclamation-circle"></i></button>';
            });
            $('#category_list').bootstrapTable('load', data);
            stop_btn('deleteCategory', 'category/changeStatus');
        }
    });

    // ThemeProduct 列表
    $('#theme_product_list').bootstrapTable({
        url: '/theme_product',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                item.status = (item.status == 1) ?
                    '<button type="button" class="btn-xs btn-primary"><i class="fa fa-check"></i></button>'
                    : '<button type="button" class="btn-xs btn-danger"><i class="fa fa-warning"></i></button>';
                item.product_name = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#detailThemeProduct" data-bid="' + item.id + '" title="查看详情"><i class="fa fa-align-justify"></i></button>';
            });
            $('#theme_product_list').bootstrapTable('load', data);
        }
    });

    // BankCard 列表
    $('#bank_card_list').bootstrapTable({
        url: '/bank_card',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                switch (item.type) {
                    case 1 :
                        item.type = '收入卡';
                        break;
                    case 2 :
                        item.type = '开支卡';
                        break;
                    case 3 :
                        item.type = '备用金';
                        break;
                    case 4 :
                        item.type = '工资卡';
                        break;
                    default :
                        item.type = '未定义卡类型';
                }
                item.status = (item.status == 1) ?
                    '<button type="button" class="btn-xs btn-primary"><i class="fa fa-check"></i></button>'
                    : '<button type="button" class="btn-xs btn-danger"><i class="fa fa-warning"></i></button>';
                item.control = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#detailCard" data-bid="' + item.id + '" title="查看详情"><i class="fa fa-align-justify"></i></button> <button type="button" class="btn-danger btn-xs" data-toggle="deleteCard"  data-bid="' + item.id + '" title="修改状态" data-list="bank_card_list"><i class="fa fa-exclamation-circle"></i></button>';
            });
            $('#bank_card_list').bootstrapTable('load', data);
            stop_btn('deleteCard', 'bank_card/changeStatus');
        }
    });

    // CardDaybook
    $('#bank_daybook_list').bootstrapTable({
        url: '/bank_daybook',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                switch (item.type) {
                    case 1 :
                        item.type = '转入';
                        break;
                    case 2 :
                        item.type = '转出';
                        break;
                    default :
                        item.type = '未定义类型';
                }
                (Number(item.income)) ? item.money = item.income : item.money = item.outlay;
                item.bank_name = item.card.bank_name;
            // rows.forEach(function (item) {
            //     item.status = (item.status == 1) ?
            //         '<button type="button" class="btn-xs btn-primary"><i class="fa fa-check"></i></button>'
            //         : '<button type="button" class="btn-xs btn-danger"><i class="fa fa-warning"></i></button>';
            //     item.product_name = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#detailThemeProduct" data-bid="' + item.id + '" title="查看详情"><i class="fa fa-align-justify"></i></button>';
            // });
            });
            $('#bank_daybook_list').bootstrapTable('load', data);
        }
    });

    // UserDaybook
    $('#user_daybook_list').bootstrapTable({
        url: '/user_daybook',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                console.log(item.type)
                switch (item.type) {
                    case 1 :
                        item.type = '转入';
                        break;
                    case 2 :
                        item.type = '转出';
                        break;
                    case 3 :
                        item.type = '内部转账';
                        break;
                    case 4 :
                        item.type = '外部调入';
                        break;
                    default :
                        item.type = '未定义类型';
                }
                // if(Number(item.income) == 0) {
                //     item.money = item.outlay;
                // }
                (Number(item.income)) ? item.money = item.income : item.money = item.outlay;
                item.username = item.user.username;
            // rows.forEach(function (item) {
            //     item.status = (item.status == 1) ?
            //         '<button type="button" class="btn-xs btn-primary"><i class="fa fa-check"></i></button>'
            //         : '<button type="button" class="btn-xs btn-danger"><i class="fa fa-warning"></i></button>';
            //     item.product_name = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#detailThemeProduct" data-bid="' + item.id + '" title="查看详情"><i class="fa fa-align-justify"></i></button>';
            // });
            });
            $('#user_daybook_list').bootstrapTable('load', data);
        }
    });

    // agent 列表
    $('#agent_list').bootstrapTable({
        url: '/agent',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                item.status = (item.status == 1) ?
                    '<button type="button" class="btn-xs btn-primary"><i class="fa fa-check"></i></button>'
                    : '<button type="button" class="btn-xs btn-danger"><i class="fa fa-warning"></i></button>';
                item.control = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#detailAgent" data-bid="' + item.id + '" title="查看详情"><i class="fa fa-align-justify"></i></button> <button type="button" class="btn-danger btn-xs" data-toggle="deleteAgent"  data-bid="' + item.id + '" title="修改状态" data-list="agent_list"><i class="fa fa-exclamation-circle"></i></button>';
            });
            $('#agent_list').bootstrapTable('load', data);
            stop_btn('deleteAgent', 'agent/changeStatus');
        }
    });

    // Message 列表
    $('#message_list').bootstrapTable({
        url: '/message',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                item.status = (item.status == 1) ?
                    '<button type="button" class="btn-xs btn-primary"><i class="fa fa-check"></i></button>'
                    : '<button type="button" class="btn-xs btn-danger"><i class="fa fa-warning"></i></button>';
                item.is_read = (item.is_read == 1) ?
                    '<button type="button" class="btn-xs btn-primary"><i class="fa fa-check"></i></button>'
                    : '<button type="button" class="btn-xs btn-danger"><i class="fa fa-warning"></i></button>';
                item.title = item.msg_title;
                item.contents = item.msg_contents;
                item.from = item.msg_from;
                item.recive_user = item.uid;
                item.send_user = item.admin_uid;
                item.send_time = item.create_time;
                item.control = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#detailMessage" data-bid="' + item.id + '" title="查看详情"><i class="fa fa-align-justify"></i></button> <button type="button" class="btn-danger btn-xs" data-toggle="deleteMessage"  data-bid="' + item.id + '" title="修改状态" data-list="message_list"><i class="fa fa-exclamation-circle"></i></button>';
            });
            $('#message_list').bootstrapTable('load', data);
            stop_btn('deleteMessage', 'message/changeStatus');
        }
    });

    // Notice 列表
    $('#notice_list').bootstrapTable({
        url: '/notice',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                item.status = (item.status == 1) ?
                    '<button type="button" class="btn-xs btn-primary"><i class="fa fa-check"></i></button>'
                    : '<button type="button" class="btn-xs btn-danger"><i class="fa fa-warning"></i></button>';
                item.contents = item.contents;
                item.start_time = item.start_time;
                item.end_time = item.end_time;
                item.sort = item.sort;
                item.control = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#detailNotice" data-bid="' + item.id + '" title="查看详情"><i class="fa fa-align-justify"></i></button> <button type="button" class="btn-danger btn-xs" data-toggle="deleteNotice"  data-bid="' + item.id + '" title="修改状态" data-list="notice_list"><i class="fa fa-exclamation-circle"></i></button>';
            });
            $('#notice_list').bootstrapTable('load', data);
            stop_btn('deleteNotice', 'notice/changeStatus');
        }
    });

    // Order 列表 状态为1未支付
    $('#order_list').bootstrapTable({
        url: '/order',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                switch(item.status){
                    case 1:
                        item.status = '<button class="btn btn-warning btn-xs demo3">未支付</button>';
                        break;
                    default:
                        item.status = '已取消';
                        break;
                }
                item.username = item.user.username;
                item.control = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#detailOrder" data-bid="' + item.id + '" title="查看详情"><i class="fa fa-align-justify"></i></button>';
            });
            $('#order_list').bootstrapTable('load', data);
        }
    });

    // Order 列表 状态为2 已支付成功未发货
    $('#order_two_list').bootstrapTable({
        url: '/order_two',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                switch(item.status){
                    case 2:
                        item.status = '<button class="btn btn-warning btn-xs demo3">已支付</button>';
                        break;
                    default:
                        item.status = '已取消';
                        break;
                }
                item.username = item.user.username;
                item.snap_items_info = '<button class="btn btn-success btn-xs demo3" data-toggle="modal" data-target="#show_info" data-bid="' + item.id + '">查看详情</button>';
                item.control = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#deliver_goods" data-bid="' + item.id + '" title="去发货">发货</button>';
            });
            $('#order_two_list').bootstrapTable('load', data);
        }
    });

    // Order 列表 状态为3 已支付成功 已发货
    $('#order_three_list').bootstrapTable({
        url: '/order_three',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                switch(item.status){
                    case 3:
                        item.status = '<button class="btn btn-warning btn-xs demo3">已发货</button>';
                        break;
                    default:
                        item.status = '已取消';
                        break;
                }
                item.username = item.user.username;
                item.control = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#collect_goods" data-bid="' + item.id + '" title="查看详情">确认收货</button>';
            });
            $('#order_three_list').bootstrapTable('load', data);
        }
    });

    // Order 列表 状态为4 已支付成功 已经确认收货
    $('#order_four_list').bootstrapTable({
        url: '/order_four',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                switch(item.status){
                    case 2:
                        item.status = '<button class="btn btn-warning btn-xs demo3">已收货</button>';
                        break;
                    default:
                        item.status = '已取消';
                        break;
                }
                item.username = item.user.username;
            });
            $('#order_four_list').bootstrapTable('load', data);
        }
    });

    // Order 列表 状态为8 已支付成功 已收货
    $('#order_eight_list').bootstrapTable({
        url: '/order_eight',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                switch(item.status){
                    case 8:
                        item.status = '<button class="btn btn-warning btn-xs demo3">已收货</button>';
                        break;
                    default:
                        item.status = '已取消';
                        break;
                }
                item.username = item.user.username;
                // item.control = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#collect_goods" data-bid="' + item.id + '" title="查看详情">确认收货</button>';
            });
            $('#order_eight_list').bootstrapTable('load', data);
        }
    });

    // Order 列表 状态为9 已支付成功 但是支付回调出错
    $('#order_nine_list').bootstrapTable({
        url: '/order_nine',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                switch(item.status){
                    case 9:
                        item.status = '<button class="btn btn-warning btn-xs demo3">发生错误</button>';
                        break;
                    default:
                        item.status = '已取消';
                        break;
                }
                item.username = item.user.username;
            });
            $('#order_nine_list').bootstrapTable('load', data);
        }
    });

    // User 列表
    $('#user_list').bootstrapTable({
        url: '/user',
        pagination:true,
        showRefresh:true,
        sidePagination:'server',
        order : 'desc',
        onLoadSuccess :function (data) {
            var rows = data.rows;
            rows.forEach(function (item) {
                item.status = (item.status == 1) ?
                    '<button type="button" class="btn-xs btn-primary"><i class="fa fa-check"></i></button>'
                    : '<button type="button" class="btn-xs btn-danger"><i class="fa fa-warning"></i></button>';
                item.agent = (item.agent == null) ? '四眼文化' : item.agent.address;
                item.g_agent = (item.g_agent == null) ? item.agent : item.g_agent.username;
                item.p_agent = (item.p_agent == null) ? item.agent : item.p_agent.username;
                item.control = '<button type="button" class="btn-xs btn-success" data-toggle="modal" data-target="#detailUser" data-bid="' + item.id + '" title="查看详情"><i class="fa fa-align-justify"></i></button> <button type="button" class="btn-danger btn-xs" data-toggle="deleteUser"  data-bid="' + item.id + '" title="修改状态" data-list="user_list"><i class="fa fa-exclamation-circle"></i></button>';
            });
            $('#user_list').bootstrapTable('load', data);
            stop_btn('deleteUser', 'user/changeStatus');
        }
    });
    
    function stop_btn(toggle_name, url) {
        $('button[data-toggle="' + toggle_name + '"]').on('click',function () {
            var id = $(this).data('bid');
            var list = $(this).data('list');
            swal({
                    title: "确定要修改此状态吗?",
                    text: "",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "确定!",
                    cancelButtonText: "取消!",
                    closeOnConfirm: false,
                    closeOnCancel: false
                },
                function(isConfirm){
                    if (isConfirm) {
                        $.ajax({
                            url : url,
                            type : 'get',
                            data : {id:id},
                            success : function (data) {
                                var swal_type = data.status == 1 ? 'success' : 'error';
                                swal(data.message, '', swal_type);
                                $('#' + list).bootstrapTable('refresh');
                            }
                        })
                    } else {
                        swal("cancel", "您取消了此动作", "error");
                    }
                });
        });
    }


})(jQuery);
